import pickle
import os
from collections import ChainMap
def savepickle(savedata,filename):


    if os.path.exists(filename) == True:
        pkl_file = open(filename, 'rb')
        data1 = pickle.load(pkl_file)
        pkl_file.close()
        filetmps = open(filename, 'wb')
        newDict = data1.copy()
        newDict.update(savedata)
        pickle.dump(newDict, filetmps)
        filetmps.close()
        pkl_file = open(filename, 'rb')
        data1 = pickle.load(pkl_file)
    else:
        filetmps = open(filename, 'wb')
        pickle.dump(savedata, filetmps)
        filetmps.close()


def lookfile(filename):
    pkl_file = open(filename, 'rb')
    data1 = pickle.load(pkl_file)
    pkl_file.close()
    return data1